package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import com.tanhua.model.dto.LikeCount;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Administrator
 */
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询电话的对象
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        return userMapper.selectOne(Wrappers.
                <User>lambdaQuery().eq(User::getMobile, mobile));
    }

    /**
     * 添加
     * @param user
     * @return
     */
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 更新数据
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /**
     * 查询所有数据
     * @return
     */
    @Override
    public List<User> findAll() {

        return userMapper.selectList(Wrappers.emptyWrapper());
    }

    /**
     * 根据UserId查询用户
     * @param userId
     * @return
     */
    @Override
    public User findById(Long userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    /**
     * 根据环信id用户名查询用户信息
     * @param huanxinId
     * @return
     */
    @Override
    public User findByHuanxin(String huanxinId) {
        LambdaQueryWrapper<User> qw=new LambdaQueryWrapper<>();
        qw.eq(User::getHxUser,huanxinId);
        User user = userMapper.selectOne(qw);
        return user;
    }

    /**
     * 修改手机号3:检查手机号
     */
    @Override
    public void updatePhone(String phone,Long userId) {
       userMapper.updatePhone(phone,userId);
    }


}